package com.xiaozhameng.bootstudy.all.connectionpooltest;

import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xiaozhameng.bootstudy.dao.UserDao;
import com.xiaozhameng.bootstudy.entity.UserEntity;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

/**
 * 验证连接池大小是否生效
 */
@Service
public class PoolSizeDemo extends ServiceImpl<UserDao, UserEntity> implements IService<UserEntity> {

    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
    public void syncData() throws InterruptedException {
        UserEntity USER = this.buildUser("测试poolSize");
        this.save(USER);

        // 暂时不提交事务

        Thread.sleep(5 * 60 * 1000);
    }

    /**
     * 构建一个user 对象
     */
    private UserEntity buildUser(String userName){
        UserEntity entity = new UserEntity();
        entity.setName(userName);
        entity.setAddress("测试-aa");
        entity.setBirthday(new Date());

        return entity ;
    }

}
